import request from '@/utils/request'

// 登录请求类型
export interface LoginData {
  username: string
  password: string
  rememberMe?: boolean
}

// 注册请求类型
export interface RegisterData {
  username: string
  password: string
  confirmPassword: string
  email: string
}

// 令牌信息类型
export interface TokenInfo {
  accessToken: string
  refreshToken: string
  tokenType: string
  expiresIn: number
  userId: number
  username: string
}

export interface LoginResponse {
  code: number
  message: string
  data: TokenInfo
  success: boolean
}

/**
 * 用户登录
 * @param data 登录数据
 * @returns TokenInfo 令牌信息
 */
export function login(data: LoginData) {
  return request({
    url: '/api/auth/login',
    method: 'post',
    data
  })
}

/**
 * 刷新令牌
 * @param refreshToken 刷新令牌
 * @returns TokenInfo 新的令牌信息
 */
export function refreshToken(refreshToken: string) {
  return request({
    url: '/api/auth/refresh',
    method: 'post',
    data: refreshToken
  }) as Promise<TokenInfo>
} 